{% load static %}
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>工厂发货类型统计</title>
    <link href="{% static 'plugins/bootstrap-5.3.0-alpha1-dist/css/bootstrap.min.css' %}" rel="stylesheet">
    <style>
        body {
            background-color: #f8fafc;
            font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
            color: #2b2d42;
            padding: 2rem;
        }

        .page-header h4 {
            margin-bottom: 1.5rem;
            text-align: center;
        }

        .chart-card {
            border: 1px solid #dee2e6;
            border-radius: 0.5rem;
            padding: 1rem;
            background-color: white;
            box-shadow: 0 2px 8px rgba(0,0,0,0.05);
            text-align: center;
        }

        .warehouse-title {
            font-size: 1.25rem;
            font-weight: bold;
            margin-bottom: 1rem;
        }

        .pie-chart-container img {
            max-width: 100%;
            height: auto;
        }

        /* 每行显示5个图表 */
        .chart-row {
            display: flex;
            flex-wrap: wrap;
            gap: 1.5rem;
            justify-content: center;
        }

        .chart-col {
            flex: 0 0 calc(20% - 1.2rem); /* 5列布局，减去gap空间 */
            min-width: 300px;
        }

        @media (max-width: 992px) {
            .chart-col {
                flex: 0 0 calc(33.333% - 1rem);
            }
        }

        @media (max-width: 768px) {
            .chart-col {
                flex: 0 0 calc(50% - 1rem);
            }
        }

        @media (max-width: 576px) {
            .chart-col {
                flex: 0 0 100%;
            }
        }
    </style>
</head>
<body>

<div class="container">
    <div class="page-header">
        <h4>工厂发货类型统计</h4>
    </div>

    {% if charts %}
        <div class="chart-row">
            {% for chart in charts %}
                <div class="chart-col">
                    <div class="chart-card">
                        <div class="warehouse-title">所属库房：{{ chart.plate }}</div>
                        <div class="pie-chart-container">
                            {% if chart.has_data %}
                                <img src="data:image/png;base64,{{ chart.pie_chart }}" alt="发货类型分布图" class="img-fluid shadow-sm rounded">
                            {% else %}
                                <p>暂无数据</p>
                            {% endif %}
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    {% else %}
        <div class="alert alert-info text-center">暂无库房数据</div>
    {% endif %}
</div>

</body>
</html>